package com.bdqn.controller;

import com.bdqn.pojo.AppInfo;
import com.bdqn.pojo.Flatform;
import com.bdqn.pojo.Status;
import com.bdqn.service.DevUserService;
import com.bdqn.util.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/dev/app")
public class DevUserController {
    
    @Resource
    private DevUserService devUserService;
    @GetMapping("/list")
    public String  list(Model model,String softwareName, Integer status, Integer flatformId,@RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex){
        List<AppInfo> appInfoList = null;
        List<Flatform> flatformList = null;
        List<Status> statusList = null;
        try {
        //总数量
        int totalCount = devUserService.count(softwareName, status, flatformId);
        //总页数
        Page page = new Page();
        page.setPageSize(page.getPageSize());
        page.setTotalCount(totalCount);// 设置一页显示数据量
        // 设置总数据量
        page.setCurrentPageNo(pageIndex);

        // 设置当前页数
        int totalPageCount = page.getTotalPageCount();

        if (pageIndex > totalPageCount) {
            pageIndex = totalPageCount;
        }
        appInfoList = devUserService.page(softwareName, status, flatformId, page);
        page.setData(appInfoList);
        model.addAttribute("appInfoList", appInfoList);  // 用户信息
        model.addAttribute("page", page); // 查询条件回显
        model.addAttribute("softwareName", softwareName); // 查询条件回显
        model.addAttribute("statusList", status);

        model.addAttribute("flatFormList", flatformId);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "developer/appinfolist";
    }

}
